//
//  CHSTwoAnimationController.m
//  ZXAnimationUtil_Example
//
//  Created by 朱新明 on 2023/9/13.
//  Copyright © 2023 simon. All rights reserved.
//

#import "CHSTwoAnimationController.h"

@interface CHSTwoAnimationController ()

@property (nonatomic, strong) UIView *view1;

@property (nonatomic, strong) CALayer *layer;

@end

@implementation CHSTwoAnimationController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    

    [self setUI];
}

- (void)setUI{
    self.navigationItem.title = @"隐式动画和显式动画";
    self.view.backgroundColor = [UIColor whiteColor];
    CGRect beginFrame = CGRectMake(100, 100, 20, 20);

    [self.view addSubview:self.view1];
    self.view1.frame = beginFrame;

    [self.view.layer addSublayer:self.layer];
    self.layer.frame = beginFrame;
}




- (UIView *)view1{
    if (!_view1) {
        UIView *view = [UIView new];
        view.layer.backgroundColor = [UIColor redColor].CGColor;
        _view1 = view;
    }
    return _view1;
}

- (CALayer *)layer{
    if (!_layer) {
        CALayer *layer = [CALayer layer];
        layer.backgroundColor = [UIColor blueColor].CGColor;
        _layer = layer;
    }
    return _layer;
}




- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
    CGRect endFrame = CGRectMake(200, 200, 20, 20);

    [UIView animateWithDuration:0.25 animations:^{
         
//        int a = (int)UIScreen.mainScreen.bounds.size.width-100;
//        CGRect rect = self.layer.frame;
//        rect.origin.x= arc4random() % a;
//        self.layer.frame = rect;
//
//        CGRect rect1 = self.view1.frame;
//        rect1.origin.y= arc4random() % 200;
//        self.view1.frame = rect1;
        self.layer.frame = endFrame;
        self.view1.frame= endFrame;
    }];
    

}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
